<style>
#simple { 

}
#complejo { 

}

</style>


<?php echo $this->Form->create('Formularios', array('url' => array('controller' => 'formularios', 'action' => 'edit'),'inputDefaults' => array('label' => false, 'div' => false))); ?>

    <div class="grid_2 titulo_campo">Nombre</div>
    <div class="grid_10">
        <?php echo $this->Form->input('Formulario.id', array('value'=>$this->data['Formulario']['id'], 'type' => 'hidden'));?>
        <?php echo $this->Form->input('Formulario.name', array('value'=>$this->data['Formulario']['name'], 'type' => 'text', 'class'=>'required'));?>
    </div>
    <div class="clear"></div>

    <div class="grid_2 titulo_campo">Descripción para publicar</div>
    <div class="grid_10">
        <?php echo $this->Form->input('Formulario.html', array('value'=>$this->data['Formulario']['html'], 'type' => 'textarea'));?>
    </div>
    <div class="clear"></div>

    <div class="grid_2 titulo_campo">
        Tipo de Formulario
    </div>
    <div class="grid_10">    
        <?php $es_complejo[0] = 'Simple'; $es_complejo[1] = 'Complejo'; ?>
        <?php echo $this->Form->select('Formulario.es_complejo', $es_complejo, null, array('escape' => false, 'empty' => false, 'class'=>'select')); ?>        
    </div>



    <div id='simple'>
        <h1>Formulario Simple</h1>
        <div class='clear'></div>
        <div class="grid_2 titulo_campo">
            Repite o Solo Uno?
        </div>
        <div class="grid_10">    
            <?php $solo_uno[0] = 'Repite'; $solo_uno[1] = 'Solo Uno';  ?>
            <?php echo $this->Form->select('Formulario.solo_uno', $solo_uno, null, array('escape' => false, 'empty' => false, 'class'=>'select')); ?>        
        </div>
        <div class='clear'></div>

        <div class="grid_2 titulo_campo">
            Es Público o Privado?
        </div>
        <div class="grid_10">    
            <?php $es_publico[0] = 'Privado'; $es_publico[1] = 'Público';  ?>
            <?php echo $this->Form->select('Formulario.es_publico', $es_publico, null, array('escape' => false, 'empty' => false, 'class'=>'select')); ?>        
        </div>
        <div class='clear'></div>

        <div class="grid_2 titulo_campo">Tag ID</div>
        <div class="grid_10">
            <?php echo $this->Form->input('Formulario.tag_id', array('value'=>$this->data['Formulario']['tag_id'], 'type' => 'text', 'class'=>'required'));?>
        </div>
        <div class="clear"></div>

            <div style='font-size:12px;font-family:"Helvetica"; background:#CCC;border:1px solid #333;padding:5px;margin-bottom:20px;'>
                <h4>Ayuda para los estilos del CSS:</h4>
<b>CLASES:</b> frm_titulo, frm_label, frm_texto, frm_booleano, frm_entero, frm_decimal, frm_memo, frm_listasimple, frm_listamultiple
    <br>
<b>ID:</b> titulo_id, label_id, texto_id, booleano_id, entero_id, decimal_id, memo_id, listasimple_id, listamultiple_id
            </div>

        <div class="grid_2 titulo_campo">Estilo CSS</div>
        <div class="grid_10">
            <?php echo $this->Form->input('Formulario.save_apply', array('value'=>'save', 'type' => 'hidden'));?>
            <?php echo $this->Form->input('Formulario.css', array(
															'value'=>$this->data['Formulario']['css'], 
															'type' => 'textarea',
															'style' => 'width:500px;',
															));?>
        </div>
        <div class="clear"></div>
    	
        <div class="grid_2 titulo_campo">jQuery Validacion</div>
        <div class="grid_10">
            <?php echo $this->Form->input('Formulario.validacion', array(
															'value'=>$this->data['Formulario']['validacion'], 
															'type' => 'textarea',
															'style' => 'width:500px;',
															));?>
        </div>
        <div class="clear"></div>
    	
    	
    	<table>
    		<thead>
    		<tr>
    			<th>Etiqueta</th>
    			<th>Tipo</th>
    			<th>Modelo</th>
    			<th>Orden</th>
    		</tr>
    		</thead>
    		<tbody>
                <?php if (isset($this->data['Formularioscampo'])){ ?>        
<?php 
                    foreach ($this->data['Formularioscampo'] as $fc){ ?>
            		<tr>
            			<td>
            				<a href="/formularios/eliminarcampo/<?php echo $this->data['Formulario']['id'];?>/<?php echo $fc['id'];?>" title='Eliminar'>[x]</a>
            				<?php echo $fc['label'];?>
            			</td>
            			<td><?php echo $fc['Campo']['Typecampo']['name'];?></td>
            			<td>
            				<?php   if (isset($fc['Campo']['Modeloformulario']['id']) ) {
            				            echo $fc['Campo']['Modeloformulario']['name'];
            				        } else { 
                                        echo "Ninguno";
                                    }
            				?>
            			</td>
            			<td>
                            <input type='text' name='ordenar[<?php echo $fc['id'];?>]' id='ordenar_<?php echo $fc['id'];?>' 
                                value='<?php echo number_format($fc['orden'],0);?>' style='width:60px;text-align:right;'>
                        </td>
            		</tr>
            	   <?php } //end foreach?>

                <?php } // end if?>    
    		</tbody>
    	</table>
    	
    	
        <div class="grid_3 titulo_campo">
    		Agregar Campo <br/>
    		<?php echo $this->Form->select('Formularioscampo.campo_id', $lista_campos, null, array('escape' => false, 'empty' => false, 'style' => 'width: 240px', 'class'=>'chzn-select')); ?>        
    	</div>
        <div class="grid_2 titulo_campo">
    		Etiqueta<br>
    		<?php echo $this->Form->input('Formularioscampo.label', array('value'=>'', 'type' => 'text'));?>
        </div>
        <div class="grid_1 titulo_campo">
    		Ancho<br>
            <?php 
                $sizes['50'] = '50';
                $sizes['75'] = '75';
                $sizes['100'] = '100';
                $sizes['150'] = '150';
                $sizes['200'] = '200';
                $sizes['250'] = '250';
            ?>
            <?php echo $this->Form->select('Formularioscampo.size', $sizes, null, array('escape' => false, 'empty' => false, 'class'=>'select')); ?>
        </div>

        <div class="grid_2 alpha omega" >
            <?php echo $this->Form->input('Formulario.add_campo', array('value'=>'add', 'type' => 'hidden'));?>
    			<input type="submit" value="Agregar" name="save">
        </div>

        <div class="grid_1" style='text-lign:right;'>
            <?php echo $this->Form->input('Formulario.ordenar', array('value'=>'ordenar', 'type' => 'hidden'));?>
                <input type="submit" value="Ordenar" name="save">
        </div>

        <div class="clear"></div>

    </div> <!-- simple -->

    <div id='complejo'>
        <h1>Formulario Complejo</h1>

        <div class="grid_4 titulo_campo">
            Listado de Formularios Disponibles<br/>
        </div>
        <div class='grid_3'>
            <?php echo $this->Form->select('Formularioscomplejos.formulario_id', $lista_formularios, null, array('escape' => false, 'empty' => false, 'class'=>'select')); ?>        
        </div>
        <div class='grid_1'>
                <input type="button" value="Agregar" name="agregar_formulario" id="agregar_formulario">
        </div>


    </div> <!-- complejo -->	

    <div class="grid_10 save">
        <?php
            $options = array('label' => 'Guardar los cambios','name' => 'save');
            echo $this->Form->end($options); 
        ?>
    </div>


</form>
<div class="clear"></div>
<script>
    jQuery(function() {
            var etiqueta = jQuery('#FormularioscampoCampoId option:selected').text();
            jQuery('#FormularioscampoLabel').val(etiqueta);

        // Si modifico el <select> del financiador 
        jQuery('#FormularioscampoCampoId').change(function(event){

            var etiqueta = jQuery('#FormularioscampoCampoId option:selected').text();
            jQuery('#FormularioscampoLabel').val(etiqueta);

        }); 

        $("#FormulariosEditForm").validate();

        var tipo_formulario = $("#FormularioEsComplejo").val();
        if (tipo_formulario==1){
            $("#complejo").show();
            $("#simple").hide();            
        } else {
            $("#simple").show();
            $("#complejo").hide();
        }


        $('#FormularioEsComplejo').change(function(){
            var selectedOption = $(this).find('option:selected');
            var tipo_formulario = selectedOption.val();
            if (tipo_formulario==1){
                $("#complejo").show();
                $("#simple").hide();            
            } else {
                $("#simple").show();
                $("#complejo").hide();
            }
            
        });

        jQuery(".chzn-select").chosen(); 
        jQuery(".chzn-select-deselect").chosen({allow_single_deselect:true});
        jQuery(".chzn-select").chosen({no_results_text: "No hay resultados"});


    }); 

</script>



<?php // pr($this->data);?>